﻿using System;
using System.Collections;
using System.Collections.Generic;
using static System.Net.Mime.MediaTypeNames;

namespace CoreTest
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            
            int[] numbers = new int[] { 211, 10, 88, 280, 326, 110, 201, 30, 250, 603, 245, 56, 8, 78, 333, 23, 433, 333, 336, 333, 333 };

            s2(numbers,200,6);
        }


        public static void s2(Array arr,int count, int size)
        {
             int length = arr.Length;


            ArrayList randArr = new ArrayList();
            int tempCount = 0;
            Random rd = new Random();
            while (true)
            {
                  int rand = rd.Next(1, length);
                rand = (int)arr.GetValue(rand);


                int isok=randArr.IndexOf(rand);
                if (isok!=-1)
                {
                    continue;
                }

                if (rand >= count) {
                    rand = count - 20;
                }
                randArr.Add(rand);

                tempCount += rand;


                if (randArr.Count>= size) {
                    
                    //如果最后结果加起来直接比count还大重来
                    if (tempCount > count && tempCount <count * 2) {
                        break;
                    } else if (tempCount > count * 2 || tempCount < count) {
                        randArr.Clear();
                        tempCount = 0;
                    }

                }
            }

            String log = "";
            foreach (int item in randArr)
            {
                log += item.ToString() + " - ";
                
            }
            Console.WriteLine(log);

           


            int time = 0;
            ArrayList tempArr = new ArrayList();
            while (true)
            {

                        time++;
                        int r = 0;

                tempArr.Clear();
                for (int index = 0;index < randArr.Count;index++){
                    int rand = rd.Next(1,(int)randArr[index]);
                    r +=rand;
                    tempArr.Add(rand);

                }
                if (r ==count){
                    
                    break;
                }


            }

            log = "";
            foreach (int item in tempArr)
            {
                log += item.ToString() + " - ";
            }

            Console.Write(log);
            Console.ReadKey();
            
        }
    }
}
